package com.polukeuro.app.client.widgets;


import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.user.client.ui.Composite;
import com.polukeuro.app.client.events.ConsummerHandler;
import com.polukeuro.app.client.events.ConsummerLoadDataEvent;
import com.polukeuro.app.client.events.ConsummerLoadErrorDataEvent;
import com.polukeuro.app.client.events.CustomErrorEvent;
import com.polukeuro.app.client.events.InitStartEvent;
import com.polukeuro.app.client.events.InitStopEvent;
import com.polukeuro.app.client.events.ProviderNeedDataEvent;
import com.polukeuro.app.client.manager.EventManager;

public abstract class ConsummerWidget extends Composite implements
		ConsummerHandler, LoadHandler {
	
	public void needData(String JSON_URL) {
		EventManager.getInstance().publish(new ProviderNeedDataEvent(JSON_URL));
	}

	@Override
	protected void onLoad() {
		// TODO Auto-generated method stub
		super.onLoad();
		EventManager.getInstance().publish(new InitStartEvent(this));
	}

	public void onLoadData() {
		EventManager.getInstance().publish(new InitStartEvent(this));
	}
	
	
	public void loadData(ConsummerLoadDataEvent event) {
		this.onLoadData();
		this.setLoadData(event);
		this.onLoadedData();
	}
	
	public abstract void setLoadData(ConsummerLoadDataEvent event) ;

	public void onLoadedData() {
		EventManager.getInstance().publish(new InitStopEvent(this));
	}

	public void loadErrorData(ConsummerLoadErrorDataEvent event) {
		EventManager.getInstance().publish(new InitStopEvent(this));
		EventManager.getInstance().publish(new CustomErrorEvent(this));
	}
	
	public void onLoad(LoadEvent event) {
		// TODO Auto-generated method stub
		
	}

}
